import fetch from 'common/src/utils/fetch';
import UTILS from "common/src/utils/utils";
// let apiPrefix = '/dev';
let apiPrefix = '/api/studentservice/';
/**
 * 分页查询
 * @param {data} data
 */
export function findListPage(data) {
  return fetch({
    url: apiPrefix + 'nameListController/page',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 * 新增
 */
export function addRequirePaperStudent(data) {
  return fetch({
    url: apiPrefix + 'nameListController/addRequirePaperStudent',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 *修改
 * @param data
 */
export function updateRequirePaperStudent(data) {
  return fetch({
    url: apiPrefix + 'nameListController/updateRequirePaperStudent',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 * 查询
 * @param data
 */
export function getRequirePaperStudentById(id) {
  return fetch({
    url: apiPrefix + 'nameListController/getRequirePaperStudentById?id=' + id,
    method: 'get'
  })
}

/**
 * 删除
 * @param id
 */
export function deleteRequirePaperStudent(id) {
  return fetch({
    url: apiPrefix + 'nameListController/deleteRequirePaperStudent?id=' + id,
    method: 'get'
  })
}

/**
 * 批量删除
 * @param id
 */
export function deleteStudentList(idList) {
  return fetch({
    url: apiPrefix + 'nameListController/deleteStudentList',
    method: 'post',
    data: {
      ids: idList
    }
  })
}

/**
 * 发布与取消发布接口
 * @param idList
 */
export function updatePublishStatus(data) {
  return fetch({
    url: apiPrefix + 'nameListController/updatePublishStatus',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 * 一次性全部发布
 */
export function updateAllPublishStatus(data) {
  return fetch({
    url: apiPrefix + 'nameListController/updateAllPublishStatus',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 * 获取名单接口
 * @param id
 */
//
export function getStudentList(calendarId, faculty, profession,deptId) {
  return fetch({
    url: apiPrefix + 'nameListController/getStudentList?calendarId=' + calendarId + "&faculty=" + faculty + "&profession=" + profession+"&deptId="+deptId,
    method: 'get'
  })
}
/**
 * 获取一直未通过名单
 * */
export function getNoPassStudentList(calendarId,faculty,profession,deptId) {
  return fetch({
    url:apiPrefix + 'nameListController/getNoPassStudentList?calendarId='+calendarId+"&faculty="+faculty+"&profession="+profession+"&deptId="+deptId,
    method: 'get'
  })
}
/*
* 根据学生学号获取学生信息
* */
export function selectStudentInfoByStuId(studentId) {
  return fetch({
    url: apiPrefix + 'nameListController/selectStudentInfoByStuId?studentId=' + studentId,
    method: 'get'
  })
}

//导出
export function exportDepartureList(data = {}) {
  let keys = Object.keys(data).map(item => { return item; });
  let params = keys.reduce((prev, curr, index) => {
    prev += curr + '=' + data[curr];
    if (index < keys.length - 1) {
      prev += '&';
    }
    return prev;
  }, '');
  let url = '/api/studentservice/nameListController/exportDepartureList';
  params && (url += `?${params}`);
  window.open(url);
}

export function exportNameList2(data) {
  return fetch({
    url: apiPrefix + 'nameListController/exportNameList2',
    method: 'post',
    data: data,
    responseType: 'blob'
  }).then(res => {
    UTILS.downloadFile(res, 'RequireNameList.xls', 'application/vnd.ms-excel;charset=utf-8');
  });
}


export default {
  findListPage,
  addRequirePaperStudent,
  updateRequirePaperStudent,
  getRequirePaperStudentById,
  deleteRequirePaperStudent,
  deleteStudentList,
  updatePublishStatus,
  updateAllPublishStatus,
  selectStudentInfoByStuId,
  exportNameList2,
  getStudentList
}


